package com.chuanke.ckfamily.action.user;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chuanke.ckfamily.action.BaseController;
import com.chuanke.ckfamily.action.base.Response;
import com.chuanke.ckfamily.service.util.IpUtil;
import com.weijie.core.util.IpAddressTransition;

@Controller
@RequestMapping("/api/comm")
public class CommonController extends BaseController {
	  private static final Logger logger = LoggerFactory.getLogger(CommonController.class);
	
	/**
	 * 是否国内ip
	 * /api/comm/get
	 * @param request
	 * @return
	 */
    @RequestMapping("/get")
    @ResponseBody
    public Response searchUser(HttpServletRequest request) {
    	Map<String,Object> result = new HashMap<>();
    	boolean isChinaIp=false;
    	try {
			String ip = IpAddressTransition.getRemoteAddr(request);
			isChinaIp = IpUtil.isChinaIp(ip);
			result.put("area", isChinaIp);
			logger.debug("isChinaIp===============>ip={},isChinaIp={}",ip,isChinaIp);
    	} catch (Exception e) {
			e.printStackTrace();
    	}
    	return new Response(result);
    }

}
